Repository navigation
Conversation
Design record for the static discovery producer of the capability registry's used.set: a call-graph scan over a world program's Roc source closure against the world_caps.rs provider catalog. Pins everything an implementer needs: inputs (entry modules, the roc-world platform tree, the linked id-core catalog), the closure / def-graph / reachability algorithm with the platform entry points as roots, the use-extraction rules (platform-module imports, capability string literals including the subscription argument form, platform builders counted when reachable), the normative over-approximation rules (dead defs excluded; a platform function passed as a value counts as used with its full emitted set, per the #5998 triage pending #5963; the direct-forwarder rule for capability parameters), and the dynamic-dispatch limitation stated explicitly (computed or runtime-loaded capability names produce an unresolved-capability diagnostic and certified: false — an explicitly marked lower bound, never a silent one). Output schema is exactly the #5958 design record's registry representation: used.static as the sorted BTreeSet<String> of catalog names keyed by a BLAKE3 build hash over the scanned closure, with catalog_commit and vocab_version provenance, so requested vs used is a plain set difference. Six worked acceptance fixtures against examples/roc-chat close the record. Spec only; no implementation. Worked by the repo-health queue worker (lane code-g, task 14829).
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 2 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 23de016aed
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| **Step 4 — Use extraction.** For each reachable def, collect: | ||
|
|
||
| - **(a) Module uses.** An `import` of a module whose name is a `PlatformModule` catalog entry (`Key`, `Screen`, `RocJson`, `RocGrid`, `RocCap`, `RocText`) adds that entry. The import counts when the importing module contains at least one reachable def. (Importing a platform module is how a program gains the module's values at all, so the module entry is used exactly when reachable code can name it.) | ||
| - **(b) Capability literals.** Every string literal in the def whose content — after stripping one optional `:<args>` suffix (the subscription argument form, e.g. `time.tick:5000`) — is a host-provider catalog name adds that name. This is the primary rule: capabilities are named as data (§Context), so the literal *is* the use site, whether it appears as a `RocCap.issue` argument, inside a `"cap"` field of a request document the def builds, or in a `subscribe` list. It applies equally to literals inside platform-module defs (the `RocCap.chat_request` builder's embedded `"chat.say"` counts when — and only when — that builder def is reachable). |
There was a problem hiding this comment.
Extract capabilities from serialized wants documents
The existing pkgs/id/examples/territory/main.roc:115 returns its entire wants document as one escaped JSON string containing a players subscription. That literal's content is not itself a catalog name, so this extraction rule omits players; because there is no computed capability expression, §5.4 also provides no reason to mark the result uncertified. An implementation following this specification would therefore certify an incomplete set for an existing world. Specify extraction from serialized wants documents, or require an uncertified result when their capability contents cannot be resolved.
Useful? React with 👍 / 👎.
|
|
||
| **Step 1 — Source closure.** Starting from the entry modules, follow `import` edges (`import pf.<Module>`, `import <Module>`) across the app tree and the platform directory until fixpoint. Every import must resolve to a file in one of the two trees; an unresolvable import is an incomplete closure → exit `2` with the unresolved edge named. Files in the trees that are never imported are not scanned. | ||
|
|
||
| **Step 2 — Def graph.** For each file in the closure, enumerate its top-level definitions (Roc `name = value` / `name : type` + definition pairs, including defs inside nominal-type namespaces such as `RocCap.{ … }` blocks). A def's identity is `(module, name)`. Build edges def → def for every identifier reference in a def's body that resolves to a top-level def in the closure (qualified `Module.name` references resolve directly; unqualified references resolve within the module, then via its imports). String literals and comments are stripped before reference extraction (but see step 4: literal extraction happens first, per def). References that resolve to Roc builtin/stdlib names (not in the closure) are leaves. |
There was a problem hiding this comment.
Preserve executable references inside string interpolations
For a reachable definition such as wants = |model| "${make_wants(model)}", stripping the string before reference extraction removes the call to make_wants. The helper is then classified as dead, and any capability literals in its request builders disappear from the supposedly certified upper bound. Roc interpolation executes ordinary expressions, as existing examples demonstrate in pkgs/id/examples/territory/main.roc:110. Strip literal text while recursively retaining references inside interpolation expressions.
Useful? React with 👍 / 👎.
| - records a diagnostic `{ file, line, column, kind: "unresolved-capability" }` in the output (§6); | ||
| - sets `certified: false` on the output. | ||
|
|
||
| A scan with any such site is an **uncertified** result: its `used_static` is a lower bound for that build, not the upper bound #5958's presentation requires, and consumers (the registry, the #5955 dynamic-loading exception policy) must treat it as such. Unknown names that are literal but absent from the catalog are **not** diagnostics: they are dropped from the set (the catalog is the vocabulary; `is_known` already teaches the runtime the same convention) — exit code `3` is reserved for a future catalog-attestation mode and is not produced by this version. Runtime-loaded code is out of the closure by definition; worlds that load code dynamically are exactly the uncertified case, and marking them — not analysing them — is this tool's whole obligation under #5955's split. |
There was a problem hiding this comment.
Avoid promising a lower bound for uncertified results
When a reachable definition contains both a capability literal in a never-taken branch and an unresolved computed request, §4 retains the former while §5.4 omits the latter. The resulting set can contain capabilities the build cannot exercise and omit capabilities it can exercise, so it is neither an upper nor a lower bound. Calling it a lower bound and requiring registry/policy consumers to treat it that way incorrectly promises that every retained member is a genuine possible use. Specify uncertified output as incomplete candidate evidence with possible false positives, rather than a guaranteed subset.
Useful? React with 👍 / 👎.
|
Closing as a duplicate of canonical PR #8448 for issue #5998 (same task 14829). PR #8499 was a second spec branch for the same task; it was diffed in full against #8448 and the salvage assessment is posted on #8448 (its unique elements — names-as-data extraction, per-site diagnostics, build_hash/catalog_commit provenance, the capscan CLI shape, and the uncertified lower-bound critique — are recorded there for the implementation follow-on). Nothing in #8499 is required for #8448: the two specs use mutually exclusive output contracts, and #8448 follows the model the triage of record fixed. #8499 is not merged; its text remains on branch queue/14829-5998-capscan-spec and in this PR. |
Closes #5998 — the used-capability derivation tool spec, per the issue's "done looks like" (a tool spec sufficient to implement without further design decisions) and the triage of record on #5998 (comment 6700990165).
Deliverable:
doc/2026-11-11_design_id5998.md(thepkgs/id/doc/design-doc location), spec only — no implementation.What it pins:
capscanbinary inpkgs/idlinkingid-core(the catalog isPROVIDER_REGISTRYfrom the same tree, never a copied list); inputs are the entry Roc modules, the roc-world platform tree, and a world id — deliberately not the declared wants or any registry state, sinceused_staticis a property of code + catalog only.importedges (unresolvable import = hard failure, no partial certification) → def graph → reachability from the platform entry points (init/update/view/wants/…) → use extraction: platform-module imports, capability string literals (including thetime.tick:5000subscription form), and platform builder defs counted exactly when reachable.unresolved-capabilitydiagnostic andcertified: false, i.e. an explicitly marked lower bound for the id: design program: worlds — advanced Roc libraries, capabilities, permissions, dynamic user functions, licensing (2026-11-04 brief) #5955 dynamic-loading exception policy to grade.used.staticas the sortedBTreeSet<String>of catalog names, keyed by a BLAKE3build_hashover the scanned closure, withcatalog_commit/vocab_versionprovenance — so requested vs used is a plain set difference and the S16 registry line needs no adapter.examples/roc-chatcovering reachability, value-passing, computed names, subscription arguments, and non-catalog literals.Premises were re-verified against current main before drafting (catalog macro/manifest shape, literal cap naming in
RocCap.issuecall sites,Wants/CapLedgerset types, the #5958 record).🤖 agent-note:v1 — queue task 14829 (lane code-g). Spec follow-on from task 14368's triage of #5998.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.